using System.Collections;
using UnityEngine;
using UnityEngine.Events;

namespace Brick
{
	public class EveryTimerManager : MonoBehaviour
	{
		public class CustomWait : CustomYieldInstruction
		{
			private UnityAction m_IntervalCallback;

			private float m_StartTime;

			private float m_LastTime;

			private float m_Interval;

			private float m_Time;

			public override bool keepWaiting
			{
				get
				{
					if (Time.time - m_StartTime >= m_Time)
					{
						return false;
					}
					if (Time.time - m_StartTime >= m_Interval)
					{
						m_LastTime = Time.time;
						m_IntervalCallback();
					}
					return true;
				}
			}

			public CustomWait(float time, float interval, UnityAction callback)
			{
				m_StartTime = Time.time;
				m_LastTime = Time.time;
				m_Interval = interval;
				m_Time = time;
				m_IntervalCallback = callback;
			}
		}

		private IEnumerator Start()
		{
			yield return new CustomWait(10f, 1f, delegate
			{
				UnityEngine.Debug.LogFormat("每过一秒回调一次:{0}", Time.time);
			});
		}
	}
}

